package com.skali.hooks;

import java.util.Enumeration;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import com.liferay.portal.kernel.struts.BaseStrutsPortletAction;
import com.liferay.portal.kernel.struts.StrutsPortletAction;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
import com.skali.portal.util.Constants;

public class ExtEditFileEntryAction extends BaseStrutsPortletAction {

	@Override
	public void processAction(StrutsPortletAction originalStrutsPortletAction,
			PortletConfig portletConfig, ActionRequest actionRequest,
			ActionResponse actionResponse) throws Exception {

		long fileEntryId = 0;
		String cmd  = ParamUtil.getString(actionRequest , Constants.CMD);
		UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
		long repositoryId = ParamUtil.getLong(uploadPortletRequest, "repositoryId");
		long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
		String sourceFileName = uploadPortletRequest.getFileName("file");
		String title = ParamUtil.getString(uploadPortletRequest, "title");
		String description = ParamUtil.getString(uploadPortletRequest, "description");
		String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");
		boolean majorVersion = ParamUtil.getBoolean(uploadPortletRequest, "majorVersion");

		long fileEntryTypeId = ParamUtil.getLong(actionRequest, "fileEntryTypeId");
		
		System.out.println(" >>> fileEntryTypeId = <<<  "+fileEntryTypeId);
		System.out.println(" >>> folderId ="+folderId +" \n title ="+title +" \n sourceFileName = "+sourceFileName);
		
		
		String address = ParamUtil.getString(uploadPortletRequest, "address");
		String telephone_no = ParamUtil.getString(uploadPortletRequest, "_20_11016telephone_no");
		String email2 = ParamUtil.getString(uploadPortletRequest, "email2");
		System.out.println(" >>> address ="+address +" \n telephone_no ="+telephone_no +" \n email2 = "+email2);
		
		
		Enumeration<String> enumParams =   actionRequest.getParameterNames();
		while(enumParams.hasMoreElements()){
			System.out.println(" \n params in action -hook "+enumParams.nextElement());
		}
		
		/*if(Validator.isNotNull(cmd)){

			if(cmd.equals(Constants.ADD)){
				System.out.println(" >>> inside ExtEditFileEntryAction --ADD <<<<");

			}else if(cmd.equals(Constants.UPDATE)){
				System.out.println(" >>> inside ExtEditFileEntryAction --UPDATE <<<<");
				fileEntryId =  ParamUtil.getLong(uploadPortletRequest, "fileEntryId");
				System.out.println(" fileEntryId  == "+fileEntryId);

			}else if(cmd.equals(Constants.UPDATE_AND_CHECKIN)){
				System.out.println(" >>> inside ExtEditFileEntryAction --UPDATE_AND_CHECKIN <<<<");
				fileEntryId =  ParamUtil.getLong(uploadPortletRequest, "fileEntryId");
				System.out.println(" fileEntryId  == "+fileEntryId);

			}

		}else{
			System.out.println(" >>> -------------------------------   <<<<");

		}*/

		//	originalStrutsPortletAction.processAction(originalStrutsPortletAction ,portletConfig, actionRequest , actionResponse);

		super.processAction(originalStrutsPortletAction, portletConfig, actionRequest,actionResponse);

		/*System.out.println(" >>> ----------Post super call---------------------   <<<<");
		if(cmd.equals(Constants.ADD)){
			System.out.println(" >>> inside ExtEditFileEntryAction -- ADD 2 <<<<");
			fileEntryId =  ParamUtil.getLong(uploadPortletRequest, "fileEntryId");
			System.out.println(" fileEntryId 2  == "+fileEntryId);
			
			ServiceContext serviceContext = ServiceContextFactory.getInstance(
					DLFileEntry.class.getName(), uploadPortletRequest);
			
		//	DLFileEntryLocalServiceUtil.
		}*/


	}

	@Override
	public String render(StrutsPortletAction originalStrutsPortletAction,
			PortletConfig portletConfig, RenderRequest renderRequest,
			RenderResponse renderResponse) throws Exception {
		// TODO Auto-generated method stub
		return originalStrutsPortletAction.render(originalStrutsPortletAction, portletConfig, renderRequest,
				renderResponse);
	}

	
	
	
/**
 *  VARIOUS Form -params in Process action...
 *  
 * 	  params in action -hook 11016address
	  params in action -hook referringPortletResource
	  params in action -hook 11016organization_name
	  params in action -hook assetLinksSearchContainerPrimaryKeys
	  params in action -hook 11016email
	  params in action -hook backURL
	  params in action -hook formDate
	 params in action -hook 11016status
	  params in action -hook folderId
	  params in action -hook title
	  params in action -hook 11016telephone_no
	  params in action -hook uploadProgressId
	  params in action -hook description
	  params in action -hook workflowAction
	 params in action -hook fileEntryTypeId
	  params in action -hook redirect
	 params in action -hook doAsGroupId
	  params in action -hook 11016sub_status
	  params in action -hook 11016tel
	  params in action -hook 11016standards_used
	  params in action -hook 11016program
	  params in action -hook uploader
	  params in action -hook 11016officer__in_charge
	  params in action -hook 11016acb_no
	  params in action -hook repositoryId 
	  params in action -hook fileEntryId
	 params in action -hook 11016fax
	  params in action -hook 11016contact
	  params in action -hook cmd
	  params in action -hook refererPlid
	  params in action -hook 11016field
	  params in action -hook assetLinkEntryIds
	  params in action -hook 11016website
	  params in action -hook struts_action
	  params in action -hook 11016email2
*/
	
	
}
